/****************************************************************************
 * Copyright 2009 Huascar A. Sanchez                                        *
 *                                                                          *
 * Licensed under the Apache License, Version 2.0 (the "License");          *
 * you may not use this file except in compliance with the License.         *
 * You may obtain a copy of the License at                                  *
 *                                                                          *
 *     http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                          *
 * Unless required by applicable law or agreed to in writing, software      *
 * distributed under the License is distributed on an "AS IS" BASIS,        *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
 * See the License for the specific language governing permissions and      *
 * limitations under the License.                                           *
 ****************************************************************************/
package com.gotobject.filter.internal;

import static com.gotobject.filter.internal.Objects.hashcode;

/**
 * @author huascar.sanchez@gmail.com (Huascar A. Sanchez)
 */
public class Pair<L, R> {
    private final L left;
    private final R right;

    private Pair(L left, R right){
        this.left  = left;
        this.right = right;
    }

    public static <L, R> Pair<L, R> of(L left, R right){
        return new Pair<L, R>(left, right);
    }

    public static <L, R> Pair<L, R> copyOf(Pair<L, R> pair){
        return new Pair<L, R>(pair.getLeft(), pair.getRight());
    }

    @Override
    public boolean equals(Object o) {
        return (o instanceof Pair) && Objects.equals(this, o);
    }

    public L getLeft() {
        return left;
    }

    public R getRight() {
        return right;
    }

    @Override
    public int hashCode() {
        return hashcode(getLeft(), getRight());
    }

    @Override
    public String toString() {
        return String.format("Pair: (%s, %s)", getLeft(), getRight());

    }
}
